package com.bangbang.blog.controller;


import com.bangbang.blog.pojo.TbDiscounts;
import com.bangbang.blog.service.impl.TbDiscountsServiceImpl;
import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-12
 */
@RestController
@RequestMapping("/blog/tbDiscounts")
public class TbDiscountsController {

    @Autowired
    private TbDiscountsServiceImpl tbDiscountsService;

    //新增
    @PostMapping
    @ApiOperation("优惠劵新增方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbDiscounts",value = "优惠劵实体类",required = true,paramType = "body")
    })
    public Result inter(@RequestBody TbDiscounts tbDiscounts){
        tbDiscountsService.insert(tbDiscounts);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //修改
    @PutMapping
    @ApiOperation("优惠劵修改方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbDiscounts",value = "优惠卷实体类",required = true,paramType = "body")
    })
    public Result update(@RequestBody TbDiscounts tbDiscounts){
        tbDiscountsService.updateById(tbDiscounts);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //删除
    @DeleteMapping
    @ApiOperation("优惠劵的删除方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "disId",value = "优惠卷id",required = true,paramType = "query")
    })
    public Result delete(@RequestParam(required = true)Long disId){
        tbDiscountsService.delete(disId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //查询
    @GetMapping
    @ApiOperation("优惠卷的查询方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "disId",value = "优惠劵id",required = true,paramType = "query")
    })
    public Result select(@RequestParam(required = true)Long disId){
        tbDiscountsService.select(disId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
}

